var over = 0;
var action = 0;

var thisPage = {
    SetPageSize: function () {
        thisPage.FetchForPage(1);
    },
    // 初始化页面
    OnPageLoad: function () {
        // 设置翻页控件
        thisPage.setPagination();

        var _pageindex = parseInt($("#PageIndex").val());
        thisPage.FetchForPage(_pageindex);
    },
    setPagination: function () {

        if (parseInt($("#TotalPages").val()) > 0) {  //总页数
            $("#wrapper__navbar").data("swPagination").options.max_page = parseInt($("#TotalPages").val());
        } else {
            $("#wrapper__navbar").data("swPagination").options.max_page = 1;
        }
        if (parseInt($("#PageIndex").val()) > 0) { //当前页数
            $("#wrapper__navbar").data("swPagination").options.current_page = parseInt($("#PageIndex").val());
            $("#wrapper__navbar").data("swPagination").setPage(parseInt($("#PageIndex").val()));
        } else {
            $("#wrapper__navbar").data("swPagination").options.current_page = 1; //当前页数
            $("#wrapper__navbar").data("swPagination").setPage(1);
        }
        var _pageindex = parseInt($("#PageIndex").val());
        $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", _pageindex);
    },
    // 得到数据列表信息
    FetchForPage: function (pageIndex) {
        var items = {};
        items["PageIndex"] = pageIndex;
        items["PageSize"] = parseInt($("#page-size").val());
        $.ajax({
            type: "POST",
            url: '/chengda/oa/bulletin/img/fetchForPage.html', ////////此处路径？       
            timeout: 60 * 1000,
            data: JSON.stringify(items),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {

            }
        }).done(function (data) {
            $("#TotalPages").val(data.TotalPages);
            $("#PageIndex").val(data.PageIndex);
            // 设置翻页控件
            thisPage.setPagination();
            //显示图片 
            var htmlstr = "";
            for (var i = 0; i < data.FilesNameList.length; i++) {
                var f = "/erpimg/ckimg";      //////getDefaultFolderFromMueasRunningData(folder);
                var fileUrl = f + "/" + data.FilesNameList[i];
                var rtnFileUrl = "ckimg/" + data.FilesNameList[i];

                var div4 = "<div style='width:100px;height:100px;float:left;word-break:break-all;padding:5px;background:#666699;margin:5px;'>"
                        + "<a href='javascript:void(0)' onclick=choose('" + data.BrowsePath + rtnFileUrl + "')>"
                        + "<img style='border:none;width:95px;height:95px;' src='" + fileUrl + "' title='" + fileUrl + "'/>"
                        + "</a>"
                        + "</div>";
                htmlstr += div4;
            }
            $("#grid__wrapper").html(htmlstr);
        }).fail(function (data) {

        }).always(function ( ) {
            thisPage.first = 1;

            // 设置当前页
            //    $.cookie("bulletin_img_list_pageindex", parseInt($("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page")));
        });
    }
};




//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    //设置分页控制
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", page);
            thisPage.FetchForPage(page);
        }
    });

    thisPage.OnPageLoad();
}
// 画面大小或者位置移动
function onPageResize() {
    var h = $(window).height();
    var w = $(window).width();

    $("#grid__wrapper").css({height: h - 60});
    $("#wrapper__navbar").css({right: 20});
}
